﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace TVersityDotNet.HelperTypes
{
    public class TVSettings
    {
        /// <summary>
        /// A boolean values indicating if the sharing should automatically start after a reboot
        /// </summary> 
        public bool AutoStart
        {
            get { return bool.Parse(this.PropertyBag.GetPropertyFromPropertyBag("autostart")); }
            set { this.PropertyBag.AddPropertyToPropertyBag("autostart", value.ToString(CultureInfo.InvariantCulture)); }
        }
        /// <summary>
        /// Maximum allowed size for cache area in megabytes
        /// </summary>                
        public int CacheSize
        {
            get { return int.Parse(this.PropertyBag.GetPropertyFromPropertyBag("cachesize"), CultureInfo.InvariantCulture); }
            set { this.PropertyBag.AddPropertyToPropertyBag("cachesize", value.ToString(CultureInfo.InvariantCulture)); }
        }
        /// <summary>
        /// How much to compress when transcoding. Possible values are: low, medium, high
        /// </summary>        
        public CompressionOption Compression
        {
            get { return (CompressionOption)Enum.Parse(typeof(CompressionOption), (string)this.PropertyBag.GetPropertyFromPropertyBag("compression"), true); }
            set { this.PropertyBag.AddPropertyToPropertyBag("compression", Enum.GetName(typeof(CompressionOption), value).ToLowerInvariant()); }
        }
        /// <summary>
        /// The quality of the connection (mainly relevant to wireless connections). Possible values are: low, medium, high
        /// </summary>
        public ConnectionQualityOption ConnectionQuality
        {
            get { return (ConnectionQualityOption)Enum.Parse(typeof(ConnectionQualityOption), (string)this.PropertyBag.GetPropertyFromPropertyBag("connectionquality"), true); }
            set { this.PropertyBag.AddPropertyToPropertyBag("connectionquality", Enum.GetName(typeof(ConnectionQualityOption), value).ToLowerInvariant()); }
        }
        /// <summary>
        /// The speed of the connection. Possible values are WIRED, WIFI_G, WIFI_B
        /// </summary>
        public ConnectionSpeedOption ConnectionSpeed
        {
            get { return (ConnectionSpeedOption)Enum.Parse(typeof(ConnectionSpeedOption), (string)this.PropertyBag.GetPropertyFromPropertyBag("connectionspeed"), true); }
            set { this.PropertyBag.AddPropertyToPropertyBag("connectionspeed", Enum.GetName(typeof(ConnectionSpeedOption), value).ToLowerInvariant()); }
        }
        /// <summary>
        /// A boolean value incdicating if the transcoding should happen as fast as possible or just as fast as needed to meet real-time playback requirements
        /// </summary>        
        public bool DisableDecodingClock
        {
            get { return bool.Parse(this.PropertyBag.GetPropertyFromPropertyBag("disabledecodingclock")); }
            set { this.PropertyBag.AddPropertyToPropertyBag("disabledecodingclock", value.ToString(CultureInfo.InvariantCulture)); }
        }
        /// <summary>
        /// A boolesan value incdicating if media with bitrate that is higher than the connection speed should be downsampled to lower bitrate
        /// </summary>
        public bool DownSampleToMatchSpeed
        {
            get { return bool.Parse(this.PropertyBag.GetPropertyFromPropertyBag("downsampletomatchspeed")); }
            set { this.PropertyBag.AddPropertyToPropertyBag("downsampletomatchspeed", value.ToString(CultureInfo.InvariantCulture)); }
        }
        /// <summary>
        /// Maximum number of items enclosed in a given feed that should be pre-downloaded (as opposed to be downloaded upon an actual request to play them)
        /// </summary>
        public int FeedDLCount
        {
            get { return int.Parse(this.PropertyBag.GetPropertyFromPropertyBag("feeddlcount"), CultureInfo.InvariantCulture); }
            set { this.PropertyBag.AddPropertyToPropertyBag("feeddlcount", value.ToString(CultureInfo.InvariantCulture)); }
        }
        /// <summary>
        /// A boolean value indicating if remote connection to the server are allowed (remote connection are connections outside the server LAN)
        /// </summary>
        public bool ListenAllowRemote
        {
            get { return bool.Parse(this.PropertyBag.GetPropertyFromPropertyBag("listenallowremote")); }
            set { this.PropertyBag.AddPropertyToPropertyBag("listenallowremote", value.ToString(CultureInfo.InvariantCulture)); }
        }
        /// <summary>
        /// The IP address of the network interface on which the server should listen (leave empty for all interfaces)
        /// </summary>
        public string ListenIP
        {
            get { return (string)this.PropertyBag.GetPropertyFromPropertyBag("listenip"); }
            set { this.PropertyBag.AddPropertyToPropertyBag("listenip", value); }
        }
        /// <summary>
        /// The TCP port on which the server should listen
        /// </summary>
        public int ListenPort
        {
            get { return int.Parse(this.PropertyBag.GetPropertyFromPropertyBag("listenport"), CultureInfo.InvariantCulture); }
            set { this.PropertyBag.AddPropertyToPropertyBag("listenport", value.ToString(CultureInfo.InvariantCulture)); }
        }
        /// <summary>
        /// A boolean values indicating if long titles should be used such tha the folder to which files belong is made a apart of the file name. This is only useful with devices that can only display one long list of items (Xbox 360 used ot be that way).
        /// </summary>
        public string LongTitle
        {
            get { return (string)this.PropertyBag.GetPropertyFromPropertyBag("longtitle"); }
            set { this.PropertyBag.AddPropertyToPropertyBag("longtitle", value); }
        }
        /// <summary>
        /// Maximum bandwidth in bps that background download are allowed to consume
        /// </summary>
        public int MaxDLBps
        {
            get { return int.Parse(this.PropertyBag.GetPropertyFromPropertyBag("maxdlbps"), CultureInfo.InvariantCulture); }
            set { this.PropertyBag.AddPropertyToPropertyBag("maxdlbps", value.ToString(CultureInfo.InvariantCulture)); }
        }
        /// <summary>
        /// Maximum number of concurrent downloads that can occur in the background
        /// </summary>
        public int MaxDLCount
        {
            get { return int.Parse(this.PropertyBag.GetPropertyFromPropertyBag("MaxDLCount".ToLowerInvariant()), CultureInfo.InvariantCulture); }
            set { this.PropertyBag.AddPropertyToPropertyBag("MaxDLCount".ToLowerInvariant(), value.ToString(CultureInfo.InvariantCulture)); }
        }
        /// <summary>
        /// Maximum number of items per RSS/ATOM/RDF feed or playlists that TVersity should display
        /// </summary>
        public int MaxItemsPerFeed
        {
            get { return int.Parse(this.PropertyBag.GetPropertyFromPropertyBag("MaxItemsPerFeed".ToLowerInvariant()), CultureInfo.InvariantCulture); }
            set { this.PropertyBag.AddPropertyToPropertyBag("MaxItemsPerFeed".ToLowerInvariant(), value.ToString(CultureInfo.InvariantCulture)); }
        }
        /// <summary>
        /// A boolean values indicating if tags should be modified for beter readibility
        /// </summary>
        public bool PrettyTags
        {
            get { return bool.Parse(this.PropertyBag.GetPropertyFromPropertyBag("PrettyTags".ToLowerInvariant())); }
            set { this.PropertyBag.AddPropertyToPropertyBag("PrettyTags".ToLowerInvariant(), value.ToString(CultureInfo.InvariantCulture)); }
        }
        /// <summary>
        /// The id of the device profile (typically a GUI but not necessarily). Special values are: autodetect never alwaysaudio c\ alwaysvideo
        /// </summary>
        public string ProfileId
        {
            get { return (string)this.PropertyBag.GetPropertyFromPropertyBag("ProfileId".ToLowerInvariant()); }
            set { this.PropertyBag.AddPropertyToPropertyBag("ProfileId".ToLowerInvariant(), value); }
        }
        /// <summary>
        /// A boolean values indicating if HTTP requests should be proxied
        /// </summary>
        public bool ProxyHttp
        {
            get { return bool.Parse(this.PropertyBag.GetPropertyFromPropertyBag("ProxyHttp".ToLowerInvariant())); }
            set { this.PropertyBag.AddPropertyToPropertyBag("ProxyHttp".ToLowerInvariant(), value.ToString(CultureInfo.InvariantCulture)); }
        }
        /// <summary>
        /// A boolean values indicating if tags should b read from AVI tags or ignored
        /// </summary>
        public bool ReadAviTags
        {
            get { return bool.Parse(this.PropertyBag.GetPropertyFromPropertyBag("ReadAviTags".ToLowerInvariant())); }
            set { this.PropertyBag.AddPropertyToPropertyBag("ReadAviTags".ToLowerInvariant(), value.ToString(CultureInfo.InvariantCulture)); }
        }
        /// <summary>
        /// The interval for subsequent automatic library refreshes (offset in minutes for midnight). A value of zero means never refresh automatically.
        /// </summary>
        public int RefreshInterval
        {
            get { return int.Parse(this.PropertyBag.GetPropertyFromPropertyBag("RefreshInterval".ToLowerInvariant()), CultureInfo.InvariantCulture); }
            set { this.PropertyBag.AddPropertyToPropertyBag("RefreshInterval".ToLowerInvariant(), value.ToString(CultureInfo.InvariantCulture)); }
        }
        /// <summary>
        /// The time of day in which automatic library refresh should be done first time after the service started (offset in minutes for midnight).
        /// </summary>
        public int RefreshStartTime
        {
            get { return int.Parse(this.PropertyBag.GetPropertyFromPropertyBag("RefreshStartTime".ToLowerInvariant()), CultureInfo.InvariantCulture); }
            set { this.PropertyBag.AddPropertyToPropertyBag("RefreshStartTime".ToLowerInvariant(), value.ToString(CultureInfo.InvariantCulture)); }
        }
        /// <summary>
        /// A boolean values indicating if items organized by folder structure should be sorted by their file name or title extracted from their tags
        /// </summary>
        public bool SortFolderByFile
        {
            get { return bool.Parse(this.PropertyBag.GetPropertyFromPropertyBag("SortFolderByFile".ToLowerInvariant())); }
            set { this.PropertyBag.AddPropertyToPropertyBag("SortFolderByFile".ToLowerInvariant(), value.ToString(CultureInfo.InvariantCulture)); }
        }
        /// <summary>
        /// The time in minutes that live streams should be cached for pausing and rewinding purposes
        /// </summary>
        public int TimeShiftInterval
        {
            get { return int.Parse(this.PropertyBag.GetPropertyFromPropertyBag("TimeShiftInterval".ToLowerInvariant()), CultureInfo.InvariantCulture); }
            set { this.PropertyBag.AddPropertyToPropertyBag("TimeShiftInterval".ToLowerInvariant(), value.ToString(CultureInfo.InvariantCulture)); }
        }
        /// <summary>
        /// The maximum height of the image resulting from transcoding
        /// </summary>
        public string TranscodeImageHeight
        {
            get { return (string)this.PropertyBag.GetPropertyFromPropertyBag("TranscodeImageHeight".ToLowerInvariant()); }
            set { this.PropertyBag.AddPropertyToPropertyBag("TranscodeImageHeight".ToLowerInvariant(), value); }
        }
        /// <summary>
        /// The maximum width of the image resulting from transcoding
        /// </summary>
        public string TranscodeImageWidth
        {
            get { return (string)this.PropertyBag.GetPropertyFromPropertyBag("TranscodeImageWidth".ToLowerInvariant()); }
            set { this.PropertyBag.AddPropertyToPropertyBag("TranscodeImageWidth".ToLowerInvariant(), value); }
        }
        /// <summary>
        /// The maximum height of the video resulting from transcoding
        /// </summary>
        public string TranscodeVideoHeight
        {
            get { return (string)this.PropertyBag.GetPropertyFromPropertyBag("TranscodeVideoHeight".ToLowerInvariant()); }
            set { this.PropertyBag.AddPropertyToPropertyBag("TranscodeVideoHeight".ToLowerInvariant(), value); }
        }
        /// <summary>
        /// The maximum width of the video resulting from transcoding
        /// </summary>
        public string TranscodeVideoWidth
        {
            get { return (string)this.PropertyBag.GetPropertyFromPropertyBag("TranscodeVideoWidth".ToLowerInvariant()); }
            set { this.PropertyBag.AddPropertyToPropertyBag("TranscodeVideoWidth".ToLowerInvariant(), value); }
        }
        /// <summary>
        /// A set of literals indicating what should be optimized. Possible values are speed, quality
        /// </summary>
        public TranscodingOptimizeOption TranscodingOptimize
        {
            get { return (TranscodingOptimizeOption)Enum.Parse(typeof(TranscodingOptimizeOption), (string)this.PropertyBag.GetPropertyFromPropertyBag("TranscodingOptimize".ToLowerInvariant()), true); }
            set { this.PropertyBag.AddPropertyToPropertyBag("TranscodingOptimize".ToLowerInvariant(), Enum.GetName(typeof(TranscodingOptimizeOption), value).ToLowerInvariant()); }
        }
        /// <summary>
        /// A set of literals indicating when to transcode. Possible values are: pprofile, never, always
        /// </summary>
        public TranscodeWhenOption TranscodingWhen
        {
            get { return (TranscodeWhenOption)Enum.Parse(typeof(TranscodeWhenOption), (string)this.PropertyBag.GetPropertyFromPropertyBag("TranscodingWhen".ToLowerInvariant()), true); }
            set { this.PropertyBag.AddPropertyToPropertyBag("TranscodingWhen".ToLowerInvariant(), Enum.GetName(typeof(TranscodeWhenOption), value).ToLowerInvariant()); }
        }
        /// <summary>
        /// A boolean values indicating if ecoding to WMV should be done via DirectShow or via ffmpeg
        /// </summary>
        public bool WMEncodedShow
        {
            get { return bool.Parse(this.PropertyBag.GetPropertyFromPropertyBag("WMEncodedShow".ToLowerInvariant())); }
            set { this.PropertyBag.AddPropertyToPropertyBag("WMEncodedShow".ToLowerInvariant(), value.ToString(CultureInfo.InvariantCulture)); }
        }
        /// <summary>
        /// The Windows Media profile to use when doing an encoding to WMV via DirectShow. Possible values are mp43, wmv7, wmv8, wmv9
        /// </summary>
        public WMProfileOption WmProfile
        {
            get { return (WMProfileOption)Enum.Parse(typeof(WMProfileOption), (string)this.PropertyBag.GetPropertyFromPropertyBag("WMProfile".ToLowerInvariant()), true); }
            set { this.PropertyBag.AddPropertyToPropertyBag("WMProfile".ToLowerInvariant(), Enum.GetName(typeof(WMProfileOption), value).ToLowerInvariant()); }
        }

        public TVSettings()
        {
            this.PropertyBag = new PropertyBag();
        }

        private PropertyBag _propertyBag;
        /// <summary>
        /// A dictionary representing the list of properties that are set. If anything isn't set, the defaults will be used
        /// </summary>
        public PropertyBag PropertyBag
        {
            get
            {
                if (this._propertyBag == null)
                    this._propertyBag = new PropertyBag();
                return this._propertyBag;
            }
            private set
            {
                this._propertyBag = value;
            }
        }
    }
}
